<template>
    <view :style="themeColor">
        <view class="page" >
    <view class="flex benben-position-layout flex flex-wrap align-center verificationLogin_flex_0"    :style="{height:(88+StatusBarRpx)+'rpx',paddingTop:StatusBarRpx+'rpx', }">
            <view   class='flex flex-wrap align-center justify-between flex-sub verificationLogin_fd0_0'      >
            <view   class='flex flex-wrap align-center verificationLogin_fd0_0_c0'   @tap.stop="handleJumpDiy" data-type="back" data-url="1"   >
        <text class='fu-iconfont2  verificationLogin_fd0_0_c0_c0'    >&#xE794;</text>
</view>
    <view   class='flex flex-wrap align-stretch justify-center'      >
        </view>
    <view   class='flex flex-wrap align-center justify-end verificationLogin_fd0_0_c0'      >
        </view>
</view>

        </view>
<view :style="{height: (88+StatusBarRpx)+'rpx'}"  ></view>
<!---flex布局flex布局开始-->
 <view class="flex flex-direction flex-wrap align-stretch benben-flex-layout verificationLogin_flex_1"    >
        <text class='verificationLogin_fd1_0'  >手机号登录/注册</text>
<text class='verificationLogin_fd1_1'  >更好的服务，登录后即可体验，未注册用户直接注册</text>
</view>
        
<!---flex布局flex布局结束-->
<!---flex布局flex布局开始-->
 <view class="flex flex-direction flex-wrap align-stretch benben-flex-layout verificationLogin_flex_2"    >
            <view   class='flex flex-wrap align-center verificationLogin_fd2_0'      >
        <image class='verificationLogin_fd2_0_c0'  mode="aspectFit"  :src='STATIC_URL+"230.png"'></image>
<input class='flex-sub verificationLogin_fd2_0_c1'   type="number" :placeholder="`请输入手机号`" confirm-type="done" :maxlength="11" placeholder-style="color:#999;font-size:32rpx"  v-model="mobile" />
</view>
    <view   class='flex flex-wrap align-center verificationLogin_fd2_1'      >
        <image class='verificationLogin_fd2_0_c0'  mode="aspectFit"  :src='STATIC_URL+"232.png"'></image>
<input class='flex-sub verificationLogin_fd2_1_c1'   type="number" :placeholder="`请输入验证码`" confirm-type="done" :maxlength="4" placeholder-style="color:#999;font-size:32rpx"  v-model="code" />
<benben-send-verification-code ref="vCode1686886333385" class=' verificationLogin_fd2_1_c2'  after-text='后重新获取' before-text='获取验证码' type='3'  :phone="mobile"></benben-send-verification-code>
</view>
<button class='verificationLogin_fd2_2'  @tap.stop="codelogonFunc()"  >立即登录</button>
    <view   class='flex flex-wrap align-center justify-center verificationLogin_fd2_3'      >
                <benben-flex-switch-new class-name='flex flex'  v-model="id_tk" :disabled='false'   >
            <template v-slot:checked>
            
    <view   class='flex flex position-relative align-center'      >
        <image class='verificationLogin_checkfd2_3_c0_c0_c0'  mode="aspectFit"  :src='STATIC_URL+"489.png"'></image>
</view>

            </template>
            <template v-slot:unchecked>
            
    <view   class='flex flex position-relative justify-end align-center'      >
        <image class='verificationLogin_noCheckfd2_3_c0_c1_c0'  mode="aspectFit"  :src='STATIC_URL+"213.png"'></image>
</view>

            </template>
        </benben-flex-switch-new>
<text class='verificationLogin_fd2_3_c1'  >注册登录即同意</text>
<text class='verificationLogin_fd2_3_c2'     @tap.stop="handleJumpDiy" data-type="navigateTo" :data-url="`/pages/dlzc/agreements/agreements`" >《用户注册协议》</text>
<text class='verificationLogin_fd2_3_c3'  >与</text>
<text class='verificationLogin_fd2_3_c2'     @tap.stop="handleJumpDiy" data-type="navigateTo" :data-url="`/pages/dlzc/privacyPolicy/privacyPolicy`" >《隐私政策》</text>
</view>
</view>
        
<!---flex布局flex布局结束-->
    
    
        </view>
    </view>
</template>
<script>
    import {validate} from '@/common/utils/validate.js'
    export default {
        components:{},
        
        
        data(){
			return {"id_tk":false,"mobile":"","code":"","dataList":{"userinfo":{"user_token":"","id":"","avatar":"","real_name":"","nickname":"","email":"","gender":"","mobile":"","birthday":"","client_id":"","phone":""}}};
		},
		computed:{
            themeColor() {
              return this.$store.getters.themeColor
            },
            
		},
		watch:{},
		onLoad(options){
            
		},
        onUnload() {
                
        },
		onReady(){
            
		},
		onShow(){
            
		},
		onHide(){
            
		},
		onResize(){
            
		},
		onPullDownRefresh(){
            
		},
		onReachBottom(e){
            
		},
		onPageScroll(e){
            
		},
		methods:{
                            //验证码登录
                async codelogonFunc(){
                                if(!validate(this.mobile,'require')){
                 this.$message.info('请输入手机号');
                 return false;
            }
            if(!validate(this.mobile,'phone')){
                 this.$message.info('请输入正确的手机号');
                 return false;
            }
            if(!validate(this.code,'require')){
                 this.$message.info('请输入验证码');
                 return false;
            }
            if(!validate(this.code,'captcha')){
                 this.$message.info('请输入正确的验证码');
                 return false;
            }
            if(this.id_tk===false){
                 this.$message.info('请勾选协议');
                 return false;
            }
    //请求方法
    //数据验证
    
  let datadataList = await this.$api.post(global.apiUrls.post5c78dca45ebc1, {
    mobile:this.mobile,code:this.code
  });
  
  if (datadataList.data.code != 1) {
    this.$message.info(datadataList.data.msg);
    return
  } 
  let infodataList = datadataList.data;
  this.dataList = infodataList.data
  
                this.$store.commit('saveToken', this.dataList.userinfo.user_token)
                this.$store.commit('updateUserInfo', this.dataList.userinfo)
                    this.$message.info('登录成功');
    this.$urouter.switchTab(`/pages/tabBar/home/home`);
                },
                //微信授权登录
                 wxLoginFunc(){
                        	if(!this.id_tk){
      		this.$message.info('请阅读并勾选《用户注册协议》和《隐私政策》');
      		return false;
      	}
      	let _this = this;
      	// #ifdef APP-PLUS
      	if (
      		plus.runtime.isApplicationExist({
      			pname: "com.tencent.mm",
      			action: "weixin://",
      		})
      	) {
      		uni.getProvider({
      			service: "oauth",
      			success: function(res) {
      				console.log(res,~res.provider.indexOf("weixin"));
      				// 如果支持微信等，就执行 wx_login_fnFunc 方法
      				if (~res.provider.indexOf("weixin")) {
      					_this.wx_login_fnFunc('weixin');
      				}
      			},
      			fail: function(err) {
      				// api错误是打印错误
      				console.log(err);
      			},
      		});
      	} else {
      		// 调起失败时提醒用户
      		this.$message.info("请安装微信后再使用此功能");
      	}
      	// #endif
                },
                //wx_login_fn方法
                 wx_login_fnFunc(){
                        console.log(type);
      	let _this = this;
      	let code = ''
      	uni.login({
      		provider: type,
      		success: (loginRes) => {
      			console.log('uni.login success-----',loginRes);
      			// code = red.code
      			uni.getUserInfo({
      				provider: type,
      				success: (infoRes) => {
      					console.log('uni.getUserInfo success-----',infoRes);
      					uni.showLoading({
      						title: "加载中...",
      					});
      					console.log('getUserInfo===', infoRes);
      					let {
      						nickName,
      						avatarUrl,
      						gender,
      						unionId,
      						openId
      					} = infoRes.userInfo;
      					console.log(JSON.stringify({openid:openId,unionid:unionId}));
      					_this.$api.post(global.apiUrls.post5d7660a421e69, {
      							extend_info:JSON.stringify({openid:openId,unionid:unionId}),
      							third_type:'wx_app'
      						})
      						.then(res => {
      							console.log('授权返回信息===',res);
      							res = res.data;
      							uni.hideLoading();
      							if (res.code == 1) {
      								if(res.data.result){//// 如果后台返回来的是 result 字段,表示此账号还没有绑定过手机号 跳转到绑定手机号页面
      									let info = {
      											unionid: unionId,
      											openid: openId,
      											gender: 0,
      											nickname: nickName,
      											avatar: avatarUrl,
      											code:code
      									}
      									uni.setStorageSync('Wxinfo_tmp', JSON.stringify(info));
      									_this.$urouter.navigateTo('/pages/dlzc/phoneNumber/phoneNumber');
      								}else if (res.data.userinfo) {// 如果后台返回的是 userinfo 字段,表示已经登录成功,把用户信息存到 store 中,
      									_this.$message.info(res.msg);
      									_this.$store.commit('updateUserInfo', res.data.userinfo);
      									_this.$store.commit('saveToken',res.data.userinfo.user_token)
      									setTimeout(() => {
      										this.$urouter.switchTab(`/pages/tabBar/home/home`);
      									}, 800);
      								}
      
      							} else if (res.code == -999) {// // 服务器解析参数错误
      								uni.hideLoading();
      								this.$message.info(result.msg);
      							} else if (res.code == -1) {
      								_this.$message.info(res.msg);
      								return
      							}
      						})
      						.catch(err => {
      							uni.hideLoading();
      							console.log(err);
      						});
      				}
      			});
      		},
      		fail: function(err) {
      			uni.hideLoading();
      			console.log(err);
      		},
      		complete(res) {
      			console.log(res);
      		}
      	});
                },
                //getProvider方法
                 getProviderFunc(){
                        uni.getProvider({
      		service: 'oauth',
      		success: res => {
      			const _provider = providers.filter(item => res.provider.includes(item.type));
      			this.providers = _provider;
      		}
      	});
                }
		}
    };
</script> 
<style lang="scss" scoped>
           .page{
            width: 100vw;
            overflow-x: hidden;
            min-height: calc(100vh - var(--window-bottom));
            background:var(--benbenbgColor1);background-size: 100% auto;
        }
    .verificationLogin_flex_0{
        background:#fff;width:750rpx;height:88rpx;overflow:hidden;z-index:10;top:0rpx;background-size:100% auto !important;
    }
    .verificationLogin_fd0_0_c0_c0{
        font-size:36rpx;color:#333;
    }
    .verificationLogin_fd0_0_c0{
        width:120rpx;
    }
    .verificationLogin_fd0_0{
        padding:0rpx 32rpx 0rpx 32rpx;
    }
    .verificationLogin_flex_1{
        margin:88rpx 48rpx 0rpx 48rpx;
    }
    .verificationLogin_fd1_1{
        color:#999999;font-size:26rpx;font-weight:500;line-height:38rpx;margin:024rpx 0rpx 0rpx 0rpx;
    }
    .verificationLogin_fd1_0{
        color:#333333;font-size:46rpx;font-weight:500;margin:0rpx 0rpx 0rpx 0rpx;
    }
    .verificationLogin_flex_2{
        padding:0rpx 56rpx 0rpx 56rpx;
    }
    .verificationLogin_fd2_3_c3{
        color:var(--benbenFontColor2);font-size:28rpx;font-weight:400;line-height:33rpx;
    }
    .verificationLogin_fd2_3_c2{
        color:var(--benbenFontColor0);font-size:28rpx;font-weight:400;line-height:33rpx;
    }
    .verificationLogin_fd2_3_c1{
        color:var(--benbenFontColor2);font-size:28rpx;font-weight:400;line-height:33rpx;margin:0rpx 0rpx 0rpx 16rpx;
    }
    .verificationLogin_noCheckfd2_3_c0_c1_c0{
        border-radius:24rpx 24rpx 24rpx 24rpx;width:30rpx;height:30rpx;
    }
    .verificationLogin_checkfd2_3_c0_c0_c0{
        width:30rpx;height:30rpx;border-radius:24rpx 24rpx 24rpx 24rpx;
    }
    .verificationLogin_fd2_3{
        position:fixed;bottom:calc(60rpx + var(--window-bottom));left:0rpx;width:750rpx;
    }
    .verificationLogin_fd2_2{
        background:var(--benbenbgColor7);border-radius:50rpx 50rpx 50rpx 50rpx;font-size:32rpx;color:#fff;width:638rpx;height:88rpx;line-height:88rpx;margin:56rpx 0rpx 0rpx 0rpx;
    }
    .verificationLogin_fd2_1_c2{
        line-height:40rpx;font-size:28rpx;color:var(--benbenFontColor8);font-weight:400;
    }
    .verificationLogin_fd2_1_c1{
        color:var(--benbenFontColor0);font-size:28rpx;font-weight:400;line-height:45rpx;margin:0rpx 0rpx 0rpx 32rpx;
    }
    .verificationLogin_fd2_1{
        border-bottom:1px solid #eee;padding:40rpx 0rpx 40rpx 0rpx;
    }
    .verificationLogin_fd2_0_c1{
        color:var(--benbenFontColor0);font-size:32rpx;font-weight:400;line-height:45rpx;margin:0rpx 0rpx 0rpx 32rpx;
    }
    .verificationLogin_fd2_0_c0{
        width:34rpx;height:34rpx;border-radius:0rpx 0rpx 0rpx 0rpx;
    }
    .verificationLogin_fd2_0{
        border-bottom:1px solid #eee;padding:40rpx 0rpx 40rpx 0rpx;margin:80rpx 0rpx 0rpx 0rpx;
    }
</style>